package com.flute.framework.autoprompt;

import com.flute.tools.data.file.ILineParser;
import com.flute.tools.util.StringUtil;

/**
 * 
 * 解析一行字符串为TokenData
 * 
 * 格式为：text SPLITER p1..pn SPLITER key
 * 
 * @author Dave Yang
 * 
 */
public class TokenDataLineParser implements ILineParser<TokenData>,
		AutoPromptConstants {
	public TokenData parse(String line) {
		if (!(StringUtil.isNullOrEmpty(line))) {
			try {
				String[] ss = line.split("tokendataspliter");
				if (ss.length > 4) {
					TokenData tt = new TokenData(ss.length - 4);
					tt.setText(ss[0]);
					tt.setKey(ss[1]);
					tt.setRecordOperator(ss[2]);
					tt.setUpdatedate(ss[3]);
					for (int i = 4; i < ss.length;) {
						try {
							tt.getPriority()[(i - 4)] = Double.valueOf(ss[i])
									.doubleValue();
						} catch (Exception e) {
							e.printStackTrace();
							System.out.println(ss[i]);
						}
						++i;
					}
					return tt;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}
}
